package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.TravelQuestion;
import cn.wolfcode.trip.base.query.TravelQuestionQuery;
import cn.wolfcode.trip.base.service.ITravelQuestionService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("travelQuestion")
public class TravelQuestionController {

    @Autowired
    private ITravelQuestionService travelQuestionService;


    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelQuestionQuery qo, Model model){
        qo.setOrderBy("t.releaseTime desc");
        model.addAttribute("result",travelQuestionService.selectForList(qo));
        return "travelQuestion/list";
    }


    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(TravelQuestion travelQuestion){
        JSONResult result = new JSONResult();
        try {
            travelQuestionService.save(travelQuestion);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
